//
//  HomeViewController.swift
//  SwiftSideslipLikeQQ
//
//  Created by JohnLui on 15/4/10.
//  Copyright (c) 2015年 com.lvwenhan. All rights reserved.
//

import UIKit

// 主页
class HomeViewController_back: UIViewController ,UITableViewDelegate,UITableViewDataSource{
    
    var titleOfOtherPages = ""

    @IBOutlet weak var contentTableView:UITableView!
    @IBOutlet var panGesture: UIPanGestureRecognizer!
    
    var topVC:TopViewController!
    var topVC1:TopViewController!
    var topVC2:TopViewController!
    

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // 设置中间 segmentView 视图
        
        topVC = TopViewController()
        topVC1 = TopViewController()
        topVC2 = TopViewController()
        
        let esView = EScrollerViewEx(frameRect: CGRect(x: 0, y: 0, width: view.frame.width, height: 300), subViewsArray: [topVC.view,topVC1.view,topVC2.view])

        self.view.addSubview(esView)
        
        topVC.circularProgressView.percentage = 0.3
        topVC1.circularProgressView.percentage = 0.9
        topVC1.circularProgressView.percentage = 0.5
        
        
        contentTableView.tableFooterView = UIView()
         self.edgesForExtendedLayout = .None
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
     // MARK: - tools button click
    @IBAction func toolsButtonClick(sender:AnyObject){
    
        let breastTag = 101
        let milkTag = 102
        let foodTag = 103
        let waterTag = 104
        let liquidTag = 105
        print(sender.tag)
        switch sender.tag{
        
        case breastTag:
            break
        case milkTag:
            break
        case foodTag:
            break
        case waterTag:
            break
        case liquidTag:
            break
        default: break
        }
        
//        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
//        let foodChoiseVc = storyBoard.instantiateViewControllerWithIdentifier("FoodChoise") as! FoodChoiseViewController
        
           let foodChoiseVc = self.storyboard?.instantiateViewControllerWithIdentifier("FoodChoise") as! FoodChoiseViewController
        
//        let bounds = UIScreen.mainScreen().bounds
//        foodChoiseVc.view.frame = CGRect(x: 0, y: bounds.height, width: bounds.width , height: bounds.height)
//        self.view.addSubview(foodChoiseVc.view)
//        UIView.animateWithDuration(0.4, animations: {
//            
//            foodChoiseVc.view.frame.origin.y = 0
//            
//            }, completion:{ (completion:Bool) in
//                
//                foodChoiseVc.updateViewConstraints()
//        })

        self.modalPresentationStyle = .CurrentContext
        self.navigationController?.modalPresentationStyle = .CurrentContext
        self.view.window?.rootViewController?.modalPresentationStyle = .CurrentContext
        self.view.window?.rootViewController?.presentViewController(foodChoiseVc, animated: true, completion: nil)
    }
    
    // MARK: - UITableViewDelegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        
        if indexPath.section == 0 && indexPath.row == 0{
            
            //self.performSegueWithIdentifier("showMilkBrandSegue", sender: self)
        }
        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
    
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        
        return nil
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
      return 4
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 0
    }
    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let identifier = "foodsContentIdentifier"
        let cell = tableView.dequeueReusableCellWithIdentifier(identifier , forIndexPath: indexPath)
        
        return cell
    }
    
    

    
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showOtherPages" {
            if let a = segue.destinationViewController as? OtherPageViewController {
                a.PageTitle = titleOfOtherPages
            }
        }
    }
    override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
        
        return true
    }
    

}
